package com.fuang.controller;

import com.fuang.bo.UserBO;
import com.fuang.service.HelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Fuang on 2017-12-21.
 */
@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private HelloService helloService;

    @RequestMapping(value = "/helloConsumer", method = RequestMethod.GET)
    public String helloConsumer(){
        //return  restTemplate.getForEntity("http://DEMOA-SERVICE/hello", String.class).getBody();
        return helloService.hello();
    }

    @HystrixCommand(fallbackMethod="helloBack")
    @RequestMapping(value = "/helloFeign", method = RequestMethod.GET)
    public String helloFeign(){
        StringBuilder sb = new StringBuilder();
        sb.append(helloService.hello()).append("\n");
        sb.append(helloService.hello1("faung")).append("\n");
        sb.append(helloService.hello2("faung", 28)).append("\n");
        sb.append(helloService.hello3(new UserBO("fuang", 28))).append("\n");
        return sb.toString();
    }

    public String helloBack(){
        return "error";
    }
}
